package com.it.controller;

import com.it.domain.ResponseResult;
import com.it.domain.entity.Article;
import com.it.service.ArticleService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

//    @GetMapping("/list")
//    public List<Article> test(){
//        return articleService.list();
//    }

    /**
     * 查询热门文章
     *
     * @return
     */
    @GetMapping("hotArticleList")
    public ResponseResult hotArticleList() {
        ResponseResult result = articleService.hotArticleList();
        return result;
    }

    /**
     * 分页查询文章
     *
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @return
     */
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum, Integer pageSize, Long categoryId) {
        return articleService.articleList(pageNum, pageSize, categoryId);
    }

    // 更新浏览量
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id) {
        return articleService.updateViewCount(id);
    }

    /**
     * 根据id查询文章
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id) {
        return articleService.getArticleDetail(id);
    }
    @GetMapping("/timeLine")
    public ResponseResult timeLine() {
        return articleService.listTimeLine();
    }

    /**
     * 获取分类与标签下的文章
     */
    @GetMapping("/where/list/{typeId}")
    public ResponseResult listCategoryArticle(
            @PathVariable("typeId") Long typeId,
            @RequestParam("type") Integer type){
        return articleService.listCategoryArticle(type, typeId);
    }
}
